package com.pathfinder.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.pathfinder.GameClient;
import com.pathfinder.R;
import com.pathfinder.model.Game;

import static com.pathfinder.RequestSender.sendCreateGameRequest;

/**
 * Date: 10.05.11
 *
 * @author Victor Passichenko (vpas@yandex-team.ru)
 */
public class CreateGameActivity extends Activity {
    public CreateGameActivity() {
        super();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.create_game);
    }

    public void onCreateGameButtonClick(View view) {
        String gameName = ((EditText) findViewById(R.id.GameNameEditText)).getText().toString();

        if (gameName != null && gameName.length() > 0) {
            Game game = new Game(gameName);
            if (sendCreateGameRequest(game, GameClient.getPlayer())) {
                GameClient.setGame(game);

                Intent intent = new Intent(this, GameLobbyActivity.class);
                startActivity(intent);
            } else {
                Toast.makeText(this, "Game with this name is already exist, choose another!", Toast.LENGTH_LONG).show();
            }
        } else {
            Toast.makeText(this, "Enter your name!", Toast.LENGTH_LONG).show();
        }
    }
}
